package resume

import (
	"context"
	"github.com/gogf/gf/v2/util/gconv"
	"resume-server/internal/model"
	"resume-server/internal/service"

	"resume-server/api/resume/v1"
)

func (c *ControllerV1) AddResume(ctx context.Context, req *v1.AddResumeReq) (res *v1.AddResumeRes, err error) {

	in := model.AddResumeInput{}
	err = gconv.Scan(req, &in)
	if err != nil {
		return nil, err
	}
	out, err := service.Resume().Create(ctx, in)
	if err != nil {
		return nil, err
	}
	res = new(v1.AddResumeRes)
	res.Id = out.Id

	return res, err
}
func (c *ControllerV1) UpdateResume(ctx context.Context, req *v1.UpdateResumeReq) (res *v1.UpdateResumeRes, err error) {

	in := model.UpdateResumeInput{}
	err = gconv.Scan(req, &in)
	if err != nil {
		return nil, err
	}

	out, err := service.Resume().Update(ctx, in)
	if err != nil {
		return nil, err
	}
	res = new(v1.UpdateResumeRes)
	err = gconv.Scan(out, res)
	if err != nil {
		return nil, err
	}

	return res, err
}
func (c *ControllerV1) GetResume(ctx context.Context, req *v1.GetResumeReq) (res *v1.GetResumeRes, err error) {

	in := model.GetResumeInput{}
	err = gconv.Scan(req, &in)
	if err != nil {
		return nil, err
	}
	out, err := service.Resume().Get(ctx, in)
	if err != nil {
		return nil, err
	}
	res = new(v1.GetResumeRes)
	err = gconv.Scan(out, res)
	if err != nil {
		return nil, err
	}

	return res, err
}
func (c *ControllerV1) GetList(ctx context.Context, req *v1.GetListReq) (res *v1.GetListRes, err error) {

	in := model.GetResumeListInput{Page: req.Page, Size: req.Size}

	list, err := service.Resume().GetList(ctx, in)
	if err != nil {
		return nil, err
	}

	res = &v1.GetListRes{}
	err = gconv.Scan(&list, res)
	if err != nil {
		return nil, err
	}
	return res, err
}
